package edu.sctu.liangyuxiang.day20150628;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * Created by user20 on 2015/6/28.
 */
public class JsonUntil {
    public Appbean jsonUntil(String json){
        JSONObject jsonObject = JSONObject.parseObject(json);
        Appbean appbean = new Appbean();

        appbean.error = jsonObject.getInteger("error");
        appbean.count = jsonObject.getString("count");
        appbean.message = jsonObject.getString("message");
        appbean.page = jsonObject.getInteger("page");
        appbean.size = jsonObject.getInteger("size");

        JSONArray list = jsonObject.getJSONArray("list");

        for (int i = 0; i <list.size() ; i++) {
            Goods goods = new Goods();
            String x = list.getString(i);
            JSONObject jsonObject1 = JSONObject.parseObject(x);
            goods.goods_id = jsonObject1.getString("goods_id");
            goods.goods_name = jsonObject1.getString("goods_name");
            goods.goods_price = jsonObject1.getString("goods_price");

            appbean.list.add(goods);
        }
        return appbean;
    }
}
